define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'reagent/index' + location.search,
                    add_url: 'reagent/add',
                    edit_url: 'reagent/edit',
                    del_url: 'reagent/del',
                    multi_url: 'reagent/multi',
                    import_url: 'reagent/import',
                    table: 'reagent',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                rowStyle:function (row,index) {
                    if (row.num <= 5) return {css: {'background-color': '#913838'}}
                    return {css: {}}
                },
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                showToggle: false,
                search:false,
                showColumns: false,
                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'code', title: __('Code'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'batch', title: __('Batch'),operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'unit_name', title: __('Unit_name'),operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'produce_time', title: __('Produce_time'),operate: false, addclass:'datetime', autocomplete:false, formatter: Table.api.formatter.date},
                        {field: 'out_time', title: __('Out_time'),operate: false, addclass:'datetime', autocomplete:false, formatter: Table.api.formatter.date},
                        {field: 'price', title: __('Price'),operate: false},
                        {field: 'supplier', title: __('Supplier'),operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'admin_name', title: __('Admin_name'),operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'outmsg', title: __('检出限'),operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'unitmsg', title: __('单位'),operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'is_use', title: __('使用状态'), operate: false,searchList: {"1":__('未使用'),"2":__('已使用')}, formatter: Table.api.formatter.normal},
                        {field: 'num', title: __('库存数量'),operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
